RemoveEventCommandHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 9 2
1
import { Inject } from '@nestjs/common';
2
import { CommandHandler } from '@nestjs/cqrs';
3
import { EventNotFoundException } from 'src/Domain/Calendar/Exception/EventNotFoundException';
4
import { IEventRepository } from 'src/Domain/Calendar/Repository/IEventRepository';
5
import { RemoveEventCommand } from './RemoveEventCommand';
6
7
@CommandHandler(RemoveEventCommand)
8
export class RemoveEventCommandHandler {
9
  constructor(
10
    @Inject('IEventRepository')
11
    private readonly eventRepository: IEventRepository,
12
  ) {}
13
14
  public async execute({ id }: RemoveEventCommand): Promise<void> {
15
    const event = await this.eventRepository.findOneById(id);
16
17
    if (!event) {
18
      throw new EventNotFoundException();
19
    }
20
21
    await this.eventRepository.remove(event);
22
  }
23
}
24